package com.xhwl.centiotdata.repair;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Copyright (C),1998-2022, 兴海物联
 * FileName: RepairContext
 * Author: XuChang
 * Date: 2022/8/9 19:18
 * Description:
 * History:
 */
@Component
public class RepairContext {

    private List<IRepairTask> list;

    private static Map<Integer, IRepairTask> taskMap;

    @Autowired
    public void setList(List<IRepairTask> list) {
        this.list = list;
    }

    @PostConstruct
    public void init() {
        taskMap = list.stream().collect(Collectors.toMap(IRepairTask::getType, a -> a));
    }

    public IRepairTask getTask(Integer type) {
        return taskMap.get(type);
    }
}
